package com.tfy.liquor.dao;

import com.tfy.liquor.bean.CartInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Mapper
@Service
public interface CartInfoDao {
    // 添加购物车
    @Insert("insert into cart_info values(null, ${userId}, '${image}', ${productId}, '${productName}', ${salesPrice}, ${num}, '${createTime}')")
    Integer addCartInfo(CartInfo cartInfo);

    // 判断购物车中该用户下是否有相同的产品信息
    @Select("select num from cart_info where userId=${userId} and productId=${productId}")
    Integer countCartInfoProductNum(CartInfo cartInfo);

    // 修改购物车中产品数量
    @Update("update cart_info set num=${num} where userId=${userId} and productId=${productId}")
    int editCartInfoProductNum(CartInfo cartInfo);

    // 获取购物车中的产品信息
    @Select("select * from cart_info where userId=${userId}")
    ArrayList<CartInfo> getCartInfoByUserId(Integer userId);

    // 根据购物车编号删除记录
    @Delete("delete from cart_info where id=${id}")
    int delCartInfoById(Integer id);

    // 根据用户编号删除记录
    @Delete("delete from cart_info where userId=${userId}")
    int delCartInfoByUserId(Integer userId);
}
